namespace Radar.Test
{
    using System;
    using NUnit.Framework;

    [TestFixture]
    public class TypeResolverTest
    {
        private static class StaticType { }
        private interface IUnimplemented { }

        private interface I1 { }
        private class C1 : I1 { }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void WillThrowOnNullKey()
        {
            TypeResolver.TryGetImplementation((string)null);
        }

        [Test, ExpectedException(typeof(ArgumentNullException))]
        public void WillThrowOnNullServiceType()
        {
            TypeResolver.TryGetImplementation((Type)null);
        }

        [Test, ExpectedException(typeof(TypeResolveException))]
        public void WillThrowOnInvalidKey()
        {
            TypeResolver.TryGetImplementation("Some invalid key");
        }

        [Test, ExpectedException(typeof(TypeResolveException))]
        public void WillThrowOnStaticType()
        {
            TypeResolver.TryGetImplementation(typeof(StaticType));
        }

        [Test, ExpectedException(typeof(TypeResolveException))]
        public void WillThrowOnNoImplementation()
        {
            TypeResolver.TryGetImplementation(typeof(IUnimplemented));
        }

        [Test]
        public void WillGetImplementingTypeByKey()
        {
            var result = TypeResolver.TryGetImplementation(typeof(I1).AssemblyQualifiedName);
            Assert.That(result, Is.EqualTo(typeof(C1)));
        }

        [Test]
        public void WillGetImplementingTypeByType()
        {
            var result = TypeResolver.TryGetImplementation(typeof(I1));
            Assert.That(result, Is.EqualTo(typeof(C1)));
        }
    }
}